from selenium import webdriver
import unittest
import time
import os

class out(unittest.TestCase):
    # 测试固件
    def setUp(self):
        print("------setUp------")
        self.driver = webdriver.Firefox()
        self.url = "https://182.254.132.183:8022/"
        self.driver.maximize_window()
        time.sleep(3)

    def tearDown(self):
        print("------tearDown------")
        self.driver.quit()

    # 已登录的登出
    def test_out1(self):
        driver = self.driver
        url = self.url
        driver.get(url)
        driver.find_element_by_xpath("/html/body/aside/section[1]/a[2]").click()
        driver.find_element_by_xpath("/html/body/main/form/input[1]").send_keys("李四")
        driver.find_element_by_xpath("/html/body/main/form/input[2]").send_keys("123")
        driver.find_element_by_xpath("/html/body/main/form/button").click()
        time.sleep(2)
        driver.find_element_by_xpath("/html/body/aside/section[1]/a[3]").click()
        time.sleep(5)
        self.assertEqual("系统必须登录后才能使用，请先登录或注册", driver.find_element_by_xpath("/html/body/main/p").text, msg="登出成功")
        time.sleep(3)

    # 未登录的登出
    def test_out2(self):
        driver = self.driver
        url = self.url
        driver.get(url)
        driver.find_element_by_xpath("/html/body/aside/section[1]/a[3]").click()
        time.sleep(5)
        self.assertEqual("系统必须登录后才能使用，请先登录或注册", driver.find_element_by_xpath("/html/body/main/p").text, msg="登出成功")
        time.sleep(3)

    if __name__ == "__main__":
        unittest.main()